/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mortbay.jetty.pico.components;

import java.util.List;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.mortbay.jetty.pico.dao.category.CategoryDAO;
import org.mortbay.jetty.pico.dao.item.ItemDAO;
import org.mortbay.jetty.pico.entities.Category;
import org.mortbay.jetty.pico.entities.Item;

/**
 *
 * @author Hnmtuan
 */
public class ViewItems {

    @Parameter(required = true)
    @Property
    private Category cateObj;
    @Property
    private Category cateEach;
    @Property
    private Item itemEach;
    @Inject
    private CategoryDAO categoryDAO;
    @Inject
    private ItemDAO itemDAO;
    @Property
    private List<Category> subCates;
    @Property
    private List<Item> listItems;

    @Inject
    private Block _leafCateContent;
    @Inject
    private Block _subCateContent;

    public Object getLayout() {
        subCates = cateObj.getCategoryList();
        if (subCates != null && subCates.size() < 1) { // this is leaf category
            // get list items
            listItems = itemDAO.getItemsByCategory(cateObj.getIdCate());
            return _leafCateContent;
        }else if (subCates == null){
            return null;
        }
        return _subCateContent;
    }

    @SetupRender
    boolean isShow() {
        return cateObj == null ? false : true;
    }
}
